﻿using STHPMS1.BLL.B_Core;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore;
using STHPMS1.ICore.I_BLL.Bus;
using STHPMS1.ICore.I_DAL;
using STHPMS1.ICore.I_Entity.Info;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.ICore.I_Serv;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace STHPMS1.BLL.B_Bus
{
    public class S_ApplyBus : BllBase, IS_ApplyBill
    {
        public void Save<T>(T entity)
            where T : class ,IS_Station
        {
            this.Scene.Dal.Sthpms1.Save(entity);
        }

        public void Remove(IS_Station entity)
        {
            this.Scene.Dal.Sthpms1.Delete(entity);
        }

        public IEnumerable<T> Get<T>(Expression<Func<T, bool>> predicate, IPagingInfo info)
            where T : class, IS_Station
        {
            return this.Scene.Dal.Sthpms1.Select<T>(predicate, info);
        }

        public IEnumerable<T> GetAll<T>() where T : class, IS_Station
        {
            return this.Scene.Dal.Sthpms1.Select<T>();
        }

        public IEnumerable<T> GetAllRdID<T>(string sid) where T : class, IS_Station
        {
            return this.Scene.Dal.Sthpms1.Select<T>(q=>q.Statid==sid);
        }

        public string SaveApplyBack(STHPMS1.ICore.I_Entity.Stmpms1.IS_Apply a)
        {
            return this.Scene.Dal.Sthpms1.S_Apply.SaveApplyBack(a);
        }
        public string SaveApply(IS_Apply apply)
        {
            string id = this.Scene.Dal.Sthpms1.Scalar<S_Apply, string>(f => f.Applyid, p => p.Apprdid == apply.Apprdid
                                                                    && p.Appbeginmp == apply.Appbeginmp
                                                                    && p.Appendmp == apply.Appendmp
                                                                    && p.Direction_Dictid == apply.Direction_Dictid);
            if (string.IsNullOrEmpty(id))
            {
                id = apply.Applyid = MyApp.Locator.GetInstance<IKeyGenrateService>().NewGuid();
                this.Scene.Dal.Sthpms1.Save<S_Apply>((S_Apply)apply);
            }

            return id;
        }

        public System.Data.DataTable GetApply(IB_Invntory b)
        {
            return  this.Scene.Dal.Sthpms1.S_Apply.GetApply(b);
        }
    }
}
